/**
 * 
 */
package sqs.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * @author kjleng
 *
 */
public class Scale implements Serializable {
	private int scaleId;
	private String scaleTitle;
	private float minValue;
	private float maxValue;
	private List<ScaleOption> scaleOptions=new ArrayList<ScaleOption>();
	
	public List<ScaleOption> getScaleOptions() {
		return scaleOptions;
	}
	public void setScaleOptions(List<ScaleOption> scaleOptions) {
		this.scaleOptions = scaleOptions;
	}
	public int getScaleId() {
		return scaleId;
	}
	public void setScaleId(int scaleId) {
		this.scaleId = scaleId;
	}
	public String getScaleTitle() {
		return scaleTitle;
	}
	public void setScaleTitle(String scaleTitle) {
		this.scaleTitle = scaleTitle;
	}
	public float getMinValue() {
		return minValue;
	}
	public void setMinValue(float minValue) {
		this.minValue = minValue;
	}
	public float getMaxValue() {
		return maxValue;
	}
	public void setMaxValue(float maxValue) {
		this.maxValue = maxValue;
	}
	
	private void computeScaleVal(){
		int optionNo = scaleOptions.size();
		float increment = (maxValue-minValue)/(optionNo-1);
		ScaleOption o1 = scaleOptions.get(0);
		o1.setOptionValue(minValue);
		ScaleOption o9 = scaleOptions.get(optionNo-1);
		o9.setOptionValue(maxValue);
		float temp=minValue;
		
		//Iterator<ScaleOption> i = scaleOptions.iterator();
		for(int i=1;i<optionNo-1;i++){
			ScaleOption o = scaleOptions.get(i);
			temp += increment;
			o.setOptionValue(temp);
		}
	}
	
	public List<Option> getRatingOptions(){
		computeScaleVal();
		List<Option> ratingOptions = new ArrayList<Option>();
		Iterator<ScaleOption> i = scaleOptions.iterator();
		while(i.hasNext()){
			ScaleOption o = i.next();
			RatingOption r = new RatingOption();
			r.setOptionText(o.getOptionText());
			r.setRating(o.getOptionValue());
			ratingOptions.add(r);
		}
		return ratingOptions;
	}
}
